package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @文件名: ActivityComtroller
 * @作者: DX
 * @创建日期: 2025/10/9
 * @描述:
 */
@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityComtroller {

    @Autowired
    private ActivityService activityService;

    @GetMapping("/type/{type}")
    public Result listByType(@PathVariable Integer type){
        log.info("查询活动列表：{}", type);
        List<Activity> list = activityService.listByType(type);
        return Result.success(list);
    }

    @PutMapping
    public Result update(@RequestBody Activity activity){
        log.info("更新活动：{}", activity);
        activityService.update(activity);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("查询活动：{}", id);
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }

    @PostMapping
    public Result add(@RequestBody Activity activity){
        log.info("添加活动：{}", activity);
        activityService.add(activity);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除活动：{}", id);
        activityService.delete(id);
        return Result.success();
    }

    @GetMapping
    public Result list(
            @RequestParam(name = "channel", required = false) Integer channel ,
            @RequestParam (name = "type" , required = false) Integer  type ,
            @RequestParam (name = "page" , defaultValue = "1") Integer page ,
            @RequestParam (name = "pageSize" , defaultValue = "10") Integer pageSize
    ) {
        log.info("查询活动列表: {},{},{},{}", channel , type, page, pageSize);
        PageResult<Activity> pageResult = activityService.pageResult(channel , type, page, pageSize);

        return Result.success(pageResult);
    }
}
